/**
 * 
 */
package com.gs.librarian.service.impl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gs.librarian.common.ApplicationException;
import com.gs.librarian.model.entity.AuditProperties;
import com.gs.librarian.model.entity.User;
import com.gs.librarian.model.vo.RegistrationVo;
import com.gs.librarian.model.vo.UserVO;
import com.gs.librarian.profile.dao.UserDao;
import com.gs.librarian.service.UserService;

/**
 * @author sabuj.das
 *
 */
@Service
public class UserServiceImpl implements UserService {

	private static Logger logger = Logger.getLogger(UserServiceImpl.class);
	
	@Autowired
	private UserDao userDao;
	
	public UserServiceImpl() {
		// TODO Auto-generated constructor stub
	}
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/* (non-Javadoc)
	 * @see com.gs.librarian.service.UserService#login(java.lang.String, java.lang.String)
	 */
	@Override
	public UserVO login(String userName, String password)
			throws ApplicationException {
		if("superuser".equalsIgnoreCase(userName)
				&& "123456".equals(password)){
			UserVO userVO = new UserVO();
			userVO.setUserName(userName);
			userVO.setPassword(password);
			return userVO;
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.gs.librarian.service.UserService#register(com.gs.librarian.model.vo.RegistrationVo)
	 */
	@Override
	public String register(RegistrationVo registrationVo)
			throws ApplicationException {
		User user = new User();
		user.setEmailId(registrationVo.getEmailId());
		user.setPassword(registrationVo.getPassword());
		user.setFirstName(registrationVo.getFirstName());
		user.setLastName(registrationVo.getLastName());
		user.setAuditProperties(AuditProperties.DEFAULT);
		
		user = getUserDao().saveUser(user);
		
		return "SUCCESS";
	}

}
